

<div class="page">
    <div class="container">
        <div class="span10 offset1" id="wrap" style="margin-top:20px;">
            <div class="row-fluid">
                <div class="span12"><strong>NOTIFIKASI</strong><br/></div>
            </div>
            <?php 
            $result = array();
            $data = "";
            //function cetak_notifikasi($output){
                if($output['notifications']!= null){
                for($count=0; $count<sizeof($output['notifications']['transaction']); $count++){
                    $notif_id = $output['notifications']['transaction'][$count]['notification_id'];
                    $trans_id = $output['notifications']['transaction'][$count]['idTransaction'];
                    $status = $output['notifications']['transaction'][$count]['status'];
                    $time = $output['notifications']['transaction'][$count]['timeStamp'];
                    $destination = $output['notifications']['transaction'][$count]['destination_label'];
                    $provider = $output['notifications']['transaction'][$count]['providerName'];
                    $providerId = $output['notifications']['transaction'][$count]['providerId'];
                    $user = $output['notifications']['transaction'][$count]['userName'];
                    $need_response = $output['notifications']['transaction'][$count]['need_response'];

                    //echo $time;

                    if($output['notifications']['transaction'][$count]){
                        if($status=='S'){         // transaksi tunai submit                  
                            if($need_response == 1){
                                //echo nicetime($time).' | ';
                                $data = 
                                $user.
                                ' ingin melakukan perjalanan dengan Anda | '.
                                anchor(site_url('/transaction/confirmProvider/'.$trans_id),'Konfirmasi').' | '.
                                anchor(site_url('/transaction/cancelTransactionProvider/'.$trans_id),'Batalkan').'';
                            } else {
                                //echo nicetime($time).' | ';
                                $data = 
                                'Permintaan terkirim. '.
                                ' Menunggu persetujuan '.
                                $provider.' | '.
                                anchor(site_url('/notifikasi/read/'.$notif_id),'OK').'';
                            }
                            
                        } else if($status=='L'){ // transaksi poin "LOCK"
                            if($providerId == $this->session->userdata('user_id')){
                                //notif pasif
                                $data = 
                                '<img class="icon-notif" src="'.base_url().'/assets/img/ic_transfer.png"> '.
                                $user.' telah mengunci poin untuk rekeningnya. <br/>'.
                                //echo anchor(site_url('/notifikasi/read/'.$notif_id),'OK').'';
                                //notif aktif
                                //echo nicetime($time).' | ';
                                $user.
                                ' ingin melakukan perjalanan dengan Anda | '.
                                anchor(site_url('/transaction/dropOff/'.$trans_id),'Konfirmasi').' | '.
                                anchor(site_url('/transaction/cancelTransactionProvider/'.$trans_id),'Batalkan').'';

                            } else  {
                                //notif pasif
                                $data = 
                                '<img class="icon-notif" src="'.base_url().'/assets/img/ic_transfer.png"> '.
                                'Poin telah dikunci server untuk '.$provider.' | '.
                                anchor(site_url('/notifikasi/read/'.$notif_id),'OK').'';
                                //notif aktif                                
                            }
                        } else if($status=='D'){ // transaksi poin "DROP OFF"
                            if($providerId == $this->session->userdata('user_id')){
                                $data = 
                                'Menunggu konfirmasi '.$user.' bahwa ia telah diantar. | '.
                                anchor(site_url('/notifikasi/read/'.$notif_id),'OK').'';
                            } else {
                                //echo nicetime($time).' | ';
                                $data = 
                                'Perjalanan dengan '.$provider.' | '.
                                anchor(site_url('/transaction/finishTransaction/'.$trans_id),'Selesai').' | '.
                                anchor(site_url('/transaction/cancelTransactionProvider/'.$trans_id),'Batalkan').'';
                            }
                        } else if($status=='C'){ // transaksi batal, baik tunai maupun poin
                            //echo nicetime($time).' | ';
                            if($providerId != $this->session->userdata('user_id')){ //user yg sdg login adalah provider
                                $data = 
                                '<img class="icon-notif" src="'.base_url().'/assets/img/ic_cancel.png"> '.
                                $provider.' '.
                                'telah membatalkan permintaan Anda | '.
                                anchor(site_url('/notifikasi/read/'.$notif_id),'OK').'';
                            } else {
                                $data = 
                                '<img class="icon-notif" src="'.base_url().'/assets/img/ic_cancel.png"> '.
                                'Anda telah membatalkan perjalanan dengan '.
                                $user.' | '.
                                anchor(site_url('/notifikasi/read/'.$notif_id),'OK').'';
                            }
                            
                        } else if($status=='F'){ // transaksi finish, baik tunai maupun poin
                            if($providerId == $this->session->userdata('user_id')){
                                $data = 
                                '<img class="icon-notif" src="'.base_url().'/assets/img/ic_bell.png"> '.
                                'Anda telah mengkonfirmasi permintaan '.
                                $user.' | '.
                                anchor(site_url('/notifikasi/read/'.$notif_id),'OK').''; 
                            } else {
                                $data = 
                                '<img class="icon-notif" src="'.base_url().'/assets/img/ic_bell.png"> '.
                                'permintaan telah dikonfirmasi. '.
                                'Anda akan pergi ke '.
                                $destination.
                                ' dengan '.
                                $provider.' | '.
                                anchor(site_url('/notifikasi/read/'.$notif_id),'OK').'';
                            }
                        }
                    }
                    //grouping notif berdasar datetime
                    if(isset($result[$time])){
                        $result[$time][] = $data;
                    } else {
                        $result[$time] = array($data);
                    }
                }
                }
                if($output['notifications']!= null and isset($output['notifications']['premium'])){
                    echo '<img class="icon-notif" src="'.base_url().'/assets/img/ic_gift_premium.png"> ';
                    echo '<strong>';
                    echo 'Selamat Anda telah terdaftar menjadi user premium. </strong> | ';
                    echo anchor(site_url('/notifikasi/read/'.$notif_id),'OK').'<br/>';
                }
                else {
                    //echo 'tidak ada notifikasi <br/>';
                }
            //}
            ?>
    <br/>
            <?php 
            foreach ($result as $key => $value) {
                echo '<strong>'.nicetime($key).'</strong><br/>';?>                
                <table class="table table-hover table-bordered" style="font-size:13px;">
            <?php
                foreach ($result[$key] as $k => $val) {
                    echo '<tr><td>';
                    echo $val.'<br/>';
                    echo '</td></tr>';
                }
                ?>
                </table>
            <?php 
            }
            ?>
            
</div>
</div>
</div>
<?php
                // $count = 0;
                // foreach ($output as $key => $value) {
                //     echo $output['notifications']['transaction'][$count]['departTime'].' | ';
                //     echo $output['notifications']['transaction'][$count]['destination_label'].' | ';
                //     echo $output['notifications']['transaction'][$count]['providerName'].' | ';
                //     echo $output['notifications']['transaction'][$count]['status'].' | ';
                //     echo '<br/>';
                //     $count++;
                // }
            ?>